package ruanjian2101.dao.impl;

import ruanjian2101.dao.UserDao;
import ruanjian2101.domain.User;
import ruanjian2101.utils.JDBCutils;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class UserDaoimpl implements UserDao {
    @Override
    public List<User> findAll() {
        /*定义数据库查询语句·*/
        String sql="select * from user2";
        ResultSet resultSet = JDBCutils.executeQuery(sql);
        List<User> users=new ArrayList<>();
        try{
            while(resultSet.next()){
                User u=new User();
                u.setId(resultSet.getInt("id"));
                u.setAddress(resultSet.getString("address"));
                u.setName(resultSet.getString("name"));
                u.setGender(resultSet.getString("gender"));
                u.setEmail(resultSet.getString("email"));
                u.setQq(resultSet.getString("qq"));
                u.setAge(resultSet.getInt("age"));
                users.add(u);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

        return users;
    }
}
